package com.adong.crowd.service.impl;

import com.adong.crowd.entity.po.MemberPO;
import com.adong.crowd.entity.po.MemberPOExample;
import com.adong.crowd.entity.vo.ProjectVO;
import com.adong.crowd.mapper.MemberPOMapper;
import com.adong.crowd.service.api.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Transactional(readOnly = true) // 在类上使用@Transactional(readOnly = true)针对查询操作设置事务属性
@Service
public class MemberServiceImpl implements MemberService {

    @Autowired
    private MemberPOMapper memberPOMapper;

    @Override
    public MemberPO getMemberPOByLoginAcct(String loginacct) {
        // 创建Example对象
        MemberPOExample memberPOExample = new MemberPOExample();
        // 创建Criteria对象
        MemberPOExample.Criteria criteria = memberPOExample.createCriteria();
        // 封装查询条件
        criteria.andLoginacctEqualTo(loginacct);
        // 执行查询
        List<MemberPO> memberList = memberPOMapper.selectByExample(memberPOExample);
        if (memberList.size() == 0 || memberList == null) {
            return null;
        }

        return memberList.get(0);
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
    @Override
    public void saveMember(MemberPO memberPO) {
        memberPOMapper.insertSelective(memberPO);
    }


}
